<?php
require_once 'duck/DuckInterface.php';
require_once 'adapt/EAdapt.php';
require_once 'duck/DuckGreen.php';
require_once 'duck/DuckRed.php';
require_once 'e/E.php';
require_once 'decker/DuckDecker.php';
require_once 'factory/DuckFactoryInterface.php';
require_once 'factory/DuckFactory.php';
require_once 'factory/CountDuckFactoryInterface.php';
require_once 'flock/FlockDuck.php';

class DuckSimulator {
    protected $ducks;

    public function setDuck(DuckInterface $d)
    {
        $this->ducks[] = $d;
    }

    public function quick()
    {
        foreach ($this->ducks as $duck)
        {
            $duck->quick();
        }
    }

    public function getQuickCount()
    {
        $count = 0;
        foreach ($this->ducks as $duck)
        {
            $count += $duck->getQuick();
        }
        return $count;
    }
}

$countDuckFactory = new CountDuckFactoryInterface();
//$simulator  = new DuckSimulator();
//
//$simulator->setDuck($countDuckFactory->createGreenDuck());
//$simulator->setDuck($countDuckFactory->createRedDuck());
//$e          = new E();
//$simulator->setDuck($countDuckFactory->createE());
//$simulator->quick();
//echo "<br>叫的次数: ";
//echo $simulator->getQuickCount();
//鸭子主群
$flock = new FlockDuck();
//创建一群鸭子
$duck1 = $countDuckFactory->createRedDuck();
$duck2 = $countDuckFactory->createGreenDuck();
$duck3 = $countDuckFactory->createRedDuck();
$duck4 = $countDuckFactory->createE();
$flock->add($duck1);
$flock->add($duck2);
$flock->add($duck3);
$flock->add($duck4);

//第5只鸭下面 生产了一群鸭子
$flock1 = new FlockDuck();
$flock1->add($countDuckFactory->createRedDuck());
$flock1->add($countDuckFactory->createGreenDuck());
//把第5只鸭子放到主群
$flock->add($flock1);

$flock->quick();